;
(function() {
	var _guide_state_arr;
	var _init_guide_state_arr = function() {
		_guide_state_arr = [];
		Object.keys(BusUserBindCon.STATE).forEach(function(key) {
			_guide_state_arr[BusUserBindCon.STATE[key]] = key;
		});
	};

	var skill = {
		save: function() {
			db.update(config.dbname.busGuide, this._id, this);
		},
		destroy: function() {
			db.remove(config.dbname.busGuide, this._id);
		},
		getDetail: function() {
			this.user = UserCon.get(this.user_id);
			if (!this.user) {
				//无效
				this.destroy();
				return null;
			} else {
				return this;
			}
		},
		//非安全，将导购的订单加入业绩中
		//必须在BUFF中进行触发
		_addAch: function(ach_id, acc) {
			var ach = AchCon.get(ach_id);
			if (!ach) {
				throwCusError("订单无效，无法加入到导购者业绩中");
			}
			if (ach.info.bus_id !== this.bus_id) {
				throwCusError("无法将此订单加入到导购记录中，商家不匹配");
			}
			if (ach.info.guide_id !== this._id) {
				throwCusError("该订单无法加入该导购者的业绩中");
			}
			var achs = this.achs || [];
			achs.push(ach_id);
			this.acc += parseFloat(acc) || 0;
			this.save();
		},
		_nextFlowStatus: function() {
			var state = +this.state;
			if (state || state == 0) {
				if (!_guide_state_arr) {
					_init_guide_state_arr();
				}
				//如果有下一个状态值，进入
				if (_guide_state_arr[state + 1]) {
					state += 1;
				}
			} else {
				throwCusError("未知的兑现状态")
			}
			console.log(state);
			this.state = state;
			this.save();
			return state;
		},
	}
	module.exports = skill;

	var db = require("../db/index");
	var GoodsCon = require("../goods/_con");
	var UserCon = require("../../core/user/_con");
	var BusCon = require("../../core/bus/_con");
	var AchCon = require("../ach/_con");
	var ClassifyCon = require("../bus.classify/_con");
	var TagCon = require("../bus.tag/_con");
	var LeagueCon = require("../league/_con");
	var BuffCon = require("../buff/_con");
	var BusUserBindCon = require("../bus_user_bind/_con");
	var BusGuideCon = require("../bus.guide/_con");
	var CommentCon = require("../comment/_con");
	var config = require("../_include/config");
	var data_cut = require("../_include/data_cut");
	var helper = require("../_include/helper");
	var md5 = require("../_include/md5");
	var $Object = require("../_include/$.Object");
	var $Array = require("../_include/$.Array");
}());